package cn.edu.lcu.cs.javateaching.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.LayoutManager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class MouseEventDemo {

	public static void main(String[] args) {
		SwingUtilities.invokeLater(() -> init());
	}

	private static void init() {
		JFrame frame = new JFrame("鼠标演示");

		frame.setSize(400, 200);
		frame.setLocation(100, 100);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(new BorderLayout());

		JTextArea textArea = new JTextArea("移动鼠标");
		textArea.setBackground(Color.yellow);
		textArea.addMouseMotionListener(new MouseMotionListener() {
			
			@Override
			public void mouseMoved(MouseEvent e) {
				textArea.setText(e.getX() + ", " + e.getY());
			}
			
			@Override
			public void mouseDragged(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		});

		frame.add(textArea, BorderLayout.CENTER);
		frame.setVisible(true);
	}

}
